package com.cbb.display.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cbb.display.entity.TodayUserConfig;
import com.cbb.display.service.TodayUserConfigService;
import com.cbb.display.util.CommonUtil;
import com.cbb.display.enums.ErrorEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bigbomb
 * @since 2020-05-28
 */
@RestController
@RequestMapping("/today-user-config")
public class TodayUserConfigController {

    @Autowired
    private TodayUserConfigService todayUserConfigService;

    @GetMapping("/get")
    public JSONObject get() {
        TodayUserConfig todayUserConfig = todayUserConfigService.getOne(null);
        return CommonUtil.successJson(todayUserConfig);

    }




    @PostMapping("/add")
    public JSONObject add(String todayuserform) {

        JSONObject jo = JSON.parseObject(todayuserform);
        TodayUserConfig todayUserConfig = JSONObject.toJavaObject(jo, TodayUserConfig.class);
       Boolean status = todayUserConfigService.updateById(todayUserConfig);
        if(status)
        {
            return CommonUtil.successJson();
        }
        else {
            return CommonUtil.errorJson(ErrorEnum.E_500);
        }
    }
}
